load("02_10_m5s_user_activity_df_univ_only_gender_stats.RData")

# ISTAT
# pop_it_internet_by_age <- load("istat_population_on_internet_by_age/pop_it_internet_by_age.RData") # Not included

# sum(pop_it_internet_by_age[1:3,]$Tot.population[pop_it_internet_by_age[1:3,]$Gender=="male"]) / 
#   (sum(pop_it_internet_by_age[1:3,]$Tot.population[pop_it_internet_by_age[1:3,]$Gender=="male"]) +
#      sum(pop_it_internet_by_age[5:7,]$Tot.population[pop_it_internet_by_age[5:7,]$Gender=="female"]))
# # [1] 0.4996327 <- Fraction male population (6-65)
# 
# sum(pop_it_internet_by_age[1:3,]$Population.on.Internet[pop_it_internet_by_age[1:3,]$Gender=="male"]) / 
#   (sum(pop_it_internet_by_age[1:3,]$Population.on.Internet[pop_it_internet_by_age[1:3,]$Gender=="male"]) +
#      sum(pop_it_internet_by_age[5:7,]$Population.on.Internet[pop_it_internet_by_age[5:7,]$Gender=="female"]))
# # [1] 0.5194831 <- Fraction male population on Internet (6-65)

# ISTAT
# Istat. (2014, October 29). Partecipazione politica. Retrieved 7 December 2014, from http://www.istat.it/it/archivio/136808
# Parla di politica  
# Tot (M + F)  	
# 52632	100.00%	
# 37243	70.76%	
# 19837	53.26%	M
# 17406	46.74%	F

# Attivita per partito  	
# Tot (M + F)		
# 52632	100.00%	
# 584	1.11%	
# 70.55%	M
# 29.45%	F


require(ggplot2)
require(gridExtra)

nms <- names(gender_sum_stats)
nms <- nms[nms!='blog_post']

myplot <- function(i) {
  plotdf <- prop.table(gender_sum_stats[[i]][1:2])
  plotdf <- data.frame(Var1 = names(plotdf),
                       Freq = as.numeric(plotdf))
  n <- sum(gender_sum_stats[[i]])
  are.NA <- gender_sum_stats[[i]][4]/n
  ggplot(plotdf, aes(Var1, Freq)) + 
    geom_bar(stat="identity") +
    scale_y_continuous(labels=scales::percent, limits=c(0,1)) +
    labs(title=i,
         y=NULL, x=paste0("n=", format(n, format="d", big.mark=','),", NA=", round(are.NA*100,2),"%")) + 
    geom_text(aes(label = sprintf("%.2f%%", Freq * 100)), 
              vjust = -.5, size=2)
  
}

#p <- lapply(nms, myplot)
#do.call("grid.arrange", c(p, ncol=5))


